package com.ds.infrastructure.hyperspace.console.service.impl;

import com.ds.infrastructure.hyperspace.console.dao.dao.TbNodeMetricsAggregationDao;
import com.ds.infrastructure.hyperspace.console.entity.page.TbPageWhere;
import com.ds.infrastructure.hyperspace.console.entity.table.TbNodeMetricsAggregation;
import com.ds.infrastructure.hyperspace.console.entity.table.TbResultMap;
import com.ds.infrastructure.hyperspace.console.entity.where.TbCustomWhere;
import com.ds.infrastructure.hyperspace.console.entity.where.TbNodeMetricsAggregationCustomWhere;
import com.ds.infrastructure.hyperspace.console.service.inf.INodeMetricsAggregationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: yaozhendong
 * @create: 2019-11-01 15:34
 **/

@Service
public class NodeMetricsAggregationService implements INodeMetricsAggregationService {
    @Autowired
    TbNodeMetricsAggregationDao tbNodeMetricsAggregationDao;

    @Override
    public int save(TbNodeMetricsAggregation record) {
        return tbNodeMetricsAggregationDao.insertSelective(record);
    }

    @Override
    public int update(TbNodeMetricsAggregation record) {
        return tbNodeMetricsAggregationDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public TbNodeMetricsAggregation get(Long id) {
        return tbNodeMetricsAggregationDao.selectByPrimaryKey(id);
    }

    @Override
    public int delete(Long id) {
        throw new IllegalStateException("no implement delete method");
    }

    @Override
    public List<TbNodeMetricsAggregation> getList(TbNodeMetricsAggregation where, TbCustomWhere customWhere, TbPageWhere pageWhere) {
        return tbNodeMetricsAggregationDao.selectListForPage(where, customWhere, pageWhere);
    }

    @Override
    public int getTotal(TbNodeMetricsAggregation where, TbCustomWhere customWhere) {
        return tbNodeMetricsAggregationDao.selectListForPageCount(where, customWhere);
    }

    @Override
    public TbNodeMetricsAggregation selectOne(TbNodeMetricsAggregation where, TbCustomWhere customWhere) {
        List<TbNodeMetricsAggregation> itemList = tbNodeMetricsAggregationDao.selectListForPage(where, customWhere, TbPageWhere.newPage4OnlyOne());
        return itemList.stream().findFirst().orElseGet(() -> null);
    }

    @Override
    public int insertList(List<TbNodeMetricsAggregation> recordList) {
        return tbNodeMetricsAggregationDao.insertList(recordList);
    }

    @Override
    public List<TbResultMap> sumRequestSecondsCount(TbCustomWhere mapWhere) {

        return tbNodeMetricsAggregationDao.sumRequestSecondsCount(mapWhere);
    }

    @Override
    public void clean(Long executeTime4EndTime) {
        TbNodeMetricsAggregationCustomWhere customWhere = new TbNodeMetricsAggregationCustomWhere().setExecuteTime4EndTime(executeTime4EndTime);
        tbNodeMetricsAggregationDao.delete(customWhere);
    }
}
